home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / Effect library / Demo ƒ / Fades ƒ / Spiral fade.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-11  |  3.1 KB  |  117 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        Spiral fade.c
  4.  
  5. Purpose:    Graphic effect to fade main window to solid pattern.
  6.             See comments below for more description.
  7.  
  8.  
  9. MSG Demo -- graphic effects demonstration program
  10. Copyright (C) 1992-4 Mark Pilgrim & Dave Blumenthal
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "msg timing.h"
  30.  
  31. #define CorrectTime 1
  32. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  33. #define theWindowWidth (boundsRect.right-boundsRect.left)
  34.  
  35. pascal short SpiralGyraFade(Rect boundsRect, Pattern *thePattern);
  36.  
  37. /* Start in the topleft corner, facing downwards.  Copy until you hit (a) the
  38.    edge of the screen, or (b) bits you've already copied.  Then turn counter-
  39.    clockwise and do it again.  */
  40.    
  41. pascal short SpiralGyraFade(Rect boundsRect, Pattern *thePattern)
  42. {
  43.     int                stop,sbottom,sleft,sright,iterrow,itercol,direction;
  44.     Rect            source;
  45.     Boolean            everyOther;
  46.     int                BOXSIZE;
  47.     RgnHandle        boundsRgn;
  48.     
  49.     boundsRgn=NewRgn();
  50.     SetRectRgn(boundsRgn, boundsRect.left, boundsRect.top, boundsRect.right, boundsRect.bottom);
  51.     BOXSIZE=theWindowHeight/15;
  52.     everyOther=FALSE;
  53.     stop=0;
  54.     sbottom=theWindowHeight/BOXSIZE-(theWindowHeight%BOXSIZE ? 0 : 1);
  55.     sleft=0;
  56.     sright=theWindowWidth/BOXSIZE-(theWindowWidth%BOXSIZE ? 0 : 1);
  57.     direction=3;
  58.     iterrow=stop;
  59.     itercol=sleft;
  60.     while ((stop<=sbottom)&&(sleft<=sright))
  61.     {
  62.         StartTiming();
  63.         source.top=iterrow*BOXSIZE;
  64.         source.bottom=source.top+BOXSIZE;
  65.         source.left=itercol*BOXSIZE;
  66.         source.right=source.left+BOXSIZE;
  67.         OffsetRect(&source, boundsRect.left, boundsRect.top);
  68.         FillRect(&source, *thePattern);
  69.         switch (direction)
  70.         {
  71.             case 0:  /* facing right */
  72.                 if (itercol==sright)
  73.                 {
  74.                     sbottom--;
  75.                     direction++;
  76.                     iterrow--;
  77.                 }
  78.                 else itercol++;
  79.                 break;
  80.             case 1:  /* facing up */
  81.                 if (iterrow==stop)   /* that reads "s top," not "stop" */
  82.                 {
  83.                     sright--;
  84.                     direction++;
  85.                     itercol--;
  86.                 }
  87.                 else iterrow--;
  88.                 break;
  89.             case 2:  /* facing left */
  90.                 if (itercol==sleft)
  91.                 {
  92.                     stop++;
  93.                     direction++;
  94.                     iterrow++;
  95.                 }
  96.                 else itercol--;
  97.                 break;
  98.             case 3:  /* facing down */
  99.                 if (iterrow==sbottom)
  100.                 {
  101.                     sleft++;
  102.                     direction=0;
  103.                     itercol++;
  104.                 }
  105.                 else iterrow++;
  106.                 break;
  107.         }
  108.         if (everyOther)
  109.             TimeCorrection(CorrectTime);
  110.         everyOther=!everyOther;
  111.     }
  112.     
  113.     DisposeRgn(boundsRgn);
  114.     
  115.     return 0;
  116. }
  117.